<?php


namespace App\Extensions\Form\Field;


use Symfony\Component\HttpFoundation\File\UploadedFile;

class MultipleFile extends \Encore\Admin\Form\Field\MultipleFile
{
    protected function generateSequenceName(UploadedFile $file): string
    {
        $index = 1;
        $extension = $file->getClientOriginalExtension();
        $original = $file->getClientOriginalName();
        $fileName = pathinfo($original,PATHINFO_FILENAME);
        $new = $original;

        while ($this->storage->exists("{$this->getDirectory()}/$new")) {
            $index++;
            $new = sprintf('%s_%s.%s', $fileName, $index, $extension);
        }

        return $new;
    }

    public function defaultDirectory()
    {
        return admin_upload_dir();
    }

}
